﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace 一起来击键
{
    public partial class 文本测试结果窗体 : Form
    {
     
        public 文本测试结果窗体(string user_input,string  str, int time)//shuzu1用户输入，shuzu2标准答案，sudu_速度，time_用时
        {
            InitializeComponent();
            int chengji = 0;
            string cuo_daan = "", cuo_qing = "";
            int correct = 0, worng = 0;
            string a = str.Replace("　　", "").Replace("\n", "");   //删掉全角空格
            string b = user_input.Replace(" ", "").Replace("\n", "");
            int input_count = user_input.Replace(" ", "").Replace("\n", "").Length;
            int sudu = (int)(input_count / (time + 0.0001) * 360);

            for (int i = 0; i < b.Length; i ++)   //对比找出错情
            {
                try
                {
                    if (a.Substring(i, 1) == b.Substring(i, 1))
                        correct = correct + 1;
                    else
                    {
                        worng = worng + 1;
                        cuo_daan = cuo_daan + a.Substring(i, 1);
                        cuo_qing = cuo_qing + b.Substring(i, 1);
                    }
                }
                catch (Exception)
                {
                    int j = 0;
                }


            }

            if (worng == 0)
                chengji = sudu;
            else if (correct / worng >= 150)
                chengji = sudu;
            else
            {
                if (correct - worng * 150 >= 0)
                    chengji = (int)correct / time * 60;
                else chengji = 0;
            }



            label6.Text = input_count.ToString();   //显示输入的总字数
            label7.Text = worng.ToString();        //显示错情个数
            label8.Text = time.ToString();        //显示时间
            label9.Text = sudu.ToString();       //显示速度
            textBox1.Text = "正确：" + cuo_daan;
            textBox2.Text = "错误：" + cuo_qing;
            label10.Text = chengji.ToString();
            if (chengji < 300)
                label13.Text = "不合格";
            else if (chengji < 350)
                label13.Text = "合格";
            else if (chengji < 400)
                label13.Text = "一般";
            else if (chengji < 450)
                label13.Text = "良好";
            else if (chengji < 500)
                label13.Text = "优秀";
            else if (chengji >= 550)
                label13.Text = "满分";
        }
       

        private void 文本测试结果窗体_Load(object sender, EventArgs e)
        {
            
        }
    }
}
